/**********************************************************************************
 * Copyright (c) 2012 - 2012,  parallel, All right reserved
 * Title: com.adc.parallel.control  InitGlobalVariable.java 
 * @author shen  shenqiao2012@163.com 
 *  2012-11-22 上午11:58:58 
 *********************************************************************************/


package com.adc.parallel.control;


import com.adc.parallel.constants.CompleteList;
import com.adc.parallel.constants.ReceiveList;
import com.adc.parallel.constants.RuntimeList;
import com.adc.parallel.constants.WaitList;
import com.adc.parallel.daemon.CompleteDaemonThread;
import com.adc.parallel.daemon.PersistentDaemonThread;
import com.adc.parallel.daemon.ReceiveDaemonThread;



/**
 * 
 * Description: 用一句话描述该文件做什么
 * @author shen  shenqiao2012@163.com 
 * @param <E>
 * @param <T>
 */
@SuppressWarnings({"unchecked","rawtypes"})
public abstract class InitGlobalVariable {
	
	private static ReceiveDaemonThread receiveDaemonThread;
	private static PersistentDaemonThread waitDaemonThread;
	private static PersistentDaemonThread runtimeDaemonThread;
	private static CompleteDaemonThread completeDaemonThread;
	
	/**
	 * 
	 * Description: initialize global vraiable
	 * author:  shen 
	 * @return void
	 */
	public static void init() {
		System.out.println("Start initialize Global Variable!");
		getReceiveDaemonThread();
		getWaitDaemonThread();
		getRuntimeDaemonThread();
		getCompleteDaemonThread();
		System.out.println("Initialize Global Variable Over!");
	}


	/**
	 * @return the receiveDaemonThread
	 */
	public static ReceiveDaemonThread getReceiveDaemonThread() {
		if (receiveDaemonThread==null) {
			receiveDaemonThread=new ReceiveDaemonThread(
					ReceiveList.getType(), ReceiveList.getReceiveList());
			receiveDaemonThread.start();
		}
		return receiveDaemonThread;
	}


	/**
	 * @return the waitDaemonThread
	 */
	public static PersistentDaemonThread getWaitDaemonThread() {
		if (waitDaemonThread==null) {
			waitDaemonThread=new PersistentDaemonThread(
					WaitList.getType(), WaitList.getWaitList());
			waitDaemonThread.start();
		}
		return waitDaemonThread;
	}


	/**
	 * @return the runtimeDaemonThread
	 */
	public static PersistentDaemonThread getRuntimeDaemonThread() {
		if (runtimeDaemonThread==null) {
			runtimeDaemonThread=new PersistentDaemonThread(
					RuntimeList.getType(), RuntimeList.getRuntimeList());
			runtimeDaemonThread.start();
		}
		return runtimeDaemonThread;
	}


	/**
	 * @return the completeDaemonThread
	 */
	public static CompleteDaemonThread getCompleteDaemonThread() {
		if (completeDaemonThread==null) {
			completeDaemonThread =new CompleteDaemonThread(
					CompleteList.getType(),CompleteList.getCompleteList());
			completeDaemonThread.start();
		}
		return completeDaemonThread;
	}

}
